package org.example.lease.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.lease.model.entities.LeaseTerm;
import org.example.lease.model.result.Result;
import org.example.lease.service.LeaseTermService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 宋孟林
 * @description
 * @date: 2025/5/14 13:38
 */
@RestController
@Slf4j
@Tag(name = "房间租期信息管理")
@RequestMapping("/admin/term")
public class LeaseTermController {
    @Resource
    private LeaseTermService leaseTermService;

    @Operation(summary = "查询全部租期列表")
    @GetMapping("/list")
    public Result<List<LeaseTerm>> listLeaseTerm(){
        List<LeaseTerm> leaseTerms = leaseTermService.list();
        return Result.ok(leaseTerms);
    }

    @PostMapping("saveOrUpdate")
    @Operation(summary = "保存或更新租期信息")
    public Result<?> saveOrUpdate(@RequestBody LeaseTerm leaseTerm) {
        leaseTermService.saveOrUpdate(leaseTerm);
        return Result.ok();
    }

    @DeleteMapping("/deleteById")
    @Operation(summary = "根据ID删除租期")
    public Result<?> deleteLeaseTermById(@RequestParam Long id) {
        leaseTermService.removeById(id);
        return Result.ok();
    }
}
